Re: Max function on Timestamp

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: Max function on Timestamp
Дата
Msg-id l03130300b3f9532becaf@[147.233.159.109]
обсуждение исходный текст
Ответ на Max function on Timestamp  ("Esteban Chiner Sanz" <echiner@tissat.es>)
Список pgsql-sql
At 11:30 +0300 on 02/09/1999, Esteban Chiner Sanz wrote:


> I have a table in my database with a timestamp field and I can't use a
> max function on it. You can do it with any other date types (date,
> timespan, etc.) but not with timestamp.
> Is there any problem on doing it? Why isn't it implemented in PostgreSQL
> 6.5.1? What would be the easiest way of doing it?

You can convert to datetime and back. I have 6.4, in which conversion from
datetime to timestamp is broken. I don't know whether or not it is broken
in 6.5.1 as well, but if it is, you can easily define:

CREATE FUNCTION dt_to_ts( datetime ) returns timestamp
AS 'SELECT timestamp_in( datetime_out( $1 ) ) WHERE $1 IS NOT NULL'
LANGUAGE 'sql';

Now, get your max with:

SELECT dt_to_ts( max( timestamp_field::datetime ) )
FROM the_table;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




В списке pgsql-sql по дате отправления:

Предыдущее
От: Dipankar Chakrabarti
Дата:
Сообщение: Re: pgsql-sql-digest V1 #344
Следующее
От: "Åíΰ³É"
Дата:
Сообщение: